home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / UNIXLIB37B / !UnixLib37 / src / signal / c / sigstack < prev    next >
Text File  |  1996-11-09  |  2KB  |  59 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/signal/c/RCS/sigstack,v $
  4.  * $Date: 1996/10/30 22:04:51 $
  5.  * $Revision: 1.1 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: sigstack,v $
  10.  * Revision 1.1  1996/10/30 22:04:51  unixlib
  11.  * Initial revision
  12.  *
  13.  ***************************************************************************/
  14.  
  15. static const char rcs_id[] = "$Id: sigstack,v 1.1 1996/10/30 22:04:51 unixlib Rel $";
  16.  
  17. /* sigstack.c: Written by Nick Burrett, 27 August 1996.
  18.    This is the BSD version of the POSIX function sigaltstack.  */
  19.  
  20. #include <signal.h>
  21. #include <errno.h>
  22. #include <unixlib/sigstate.h>
  23. #include <sys/unix.h>
  24.  
  25. /* Specifies an alternate stack for use during signal handling.
  26.    When a signal is received by the process and its action
  27.    indicates that the signal stack is used, the system arranges
  28.    a switch to the currently installed signal stack while the
  29.    handler for that signal is executed.  */
  30.  
  31. int
  32. sigstack (const struct sigstack *stack, struct sigstack *oldstack)
  33. {
  34.   struct unixlib_sigstate *ss = &__u->sigstate;
  35.   if (ss->signalstack.ss_flags & SA_ONSTACK)
  36.     {
  37.       /* Trying to disable a stack that is currently in use.  */
  38.       errno = EINVAL;
  39.       return -1;
  40.     }
  41.  
  42.   if (oldstack != NULL)
  43.     {
  44.       oldstack->ss_sp = ss->signalstack.ss_sp;
  45.       oldstack->ss_onstack = ss->signalstack.ss_flags & SA_ONSTACK;
  46.     }
  47.   /* Converting between a sigstack and a sigaltstack.  With sigstack,
  48.      ss_sp points to the top of the buffer because we have a downwards
  49.      growing stack. Since we don't have a size parameter, we'll set
  50.      size to -1 to tell the signal handler that ss_sp points to the
  51.      top of the buffer, instead of the bottom.  */
  52.  
  53.   ss->signalstack.ss_sp = stack->ss_sp;
  54.   ss->signalstack.ss_size = -1;
  55.   ss->signalstack.ss_flags = stack->ss_onstack;
  56.  
  57.   return 0;
  58. }
  59.